package servlets;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import managers.EventManager;

public class AddPointServlet extends HttpServlet {
	private String schemaName;
	private String secretKey;
	private static final long serialVersionUID = 3453091955573157294L;	
 	
	/**
	 * This method initialize the schema name
	 */
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
        ServletContext servletContext;
        servletContext = getServletContext(); 
        schemaName = servletContext.getInitParameter("SchemaName");
        secretKey = servletContext.getInitParameter("SecretKey");
     }
	
	
	protected void doPut(HttpServletRequest request, HttpServletResponse response){

		
		System.setProperty("jsse.enableSNIExtension", "false");

		String idSeller,idFeedback;
		EventManager em = new EventManager();
		
		idSeller=request.getParameter("idSeller"); 
		
		idFeedback = request.getParameter("idFeedback");
		
		try {	
			if(!em.addEvent(idSeller,idFeedback,schemaName, secretKey)) 
				response.getWriter().write("{\n\t\"errors\":\"no\"\n}");
			else
				response.getWriter().write("{\n\t\"errors\":\"yes\"\n}");
			}
		catch (Exception e) {
			try {
				response.getWriter().write("{\n\t\"errors\":\"yes\"\n}");
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	}
}
